<% title _("Subnets") %>

<%= javascript 'subnets' %>
<% title_actions render_pagelets_for(:subnet_index_title_buttons) %>
<% title_actions new_link(_("Create Subnet")) %>

<table class="<%= table_css_classes 'table-fixed' %>">
  <thead>
    <tr>
      <th class="col-md-2"><%= sort :name, :as => s_("Subnet|Name") %></th>
      <th class="col-md-2"><%= sort :network, :as => s_("Subnet|Network") %></th>
      <th class="col-md-3"><%= _("Domains") %></th>
      <th class="col-md-1"><%= sort :vlanid, :as => s_('Subnet|Vlanid') %></th>
      <th class="col-md-2"><%= _("DHCP Proxy") %></th>
      <th class="col-md-1"><%= _("Hosts") %></th>
      <th><%= _('Actions') %></th>
    </tr>
  </thead>
  <tbody>
    <% @subnets.each do |subnet| %>
      <tr>
        <td class="ellipsis"><%=link_to_if_authorized subnet.name, hash_for_edit_subnet_path(:id => subnet).merge(:auth_object => subnet, :authorizer => authorizer) %></td>
        <td><%=subnet.network_address %></td>
        <td class="ellipsis"><%= subnet.domains.map(&:name).to_sentence %></td>
        <td><%= subnet.vlanid %></td>
        <td class="ellipsis"><%= subnet.dhcp %></td>
        <td>
          <%=
            # TODO: https://projects.theforeman.org/issues/36517 this only works for IPv4
            count = hosts_count[subnet]
            search_key = subnet.type == 'Subnet::Ipv6' ? 'subnet6.name' : 'subnet.name'
            link_to_if_authorized(count, hash_for_hosts_path(:search => "#{search_key}=\"#{subnet}\""))
          %>
        </td>
        <td class="col-md-1">
          <%= action_buttons(display_delete_if_authorized(
                               hash_for_subnet_path(:id => subnet).
                               merge(:auth_object => subnet, :authorizer => authorizer),
                               :data => { :confirm => _("Delete %s?") % subnet.name }),
                             render_pagelets_for(:subnet_index_action_buttons, subject: subnet)
              ) %>
        </td>
      </tr>
    <% end %>
  </tbody>
</table>
<%= will_paginate_with_info @subnets %>
